package com.spider.hhtplat;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.util.Cookie;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.Assert;

import java.io.IOException;

//@SpringBootApplication
public class HhtplatApplication {

    public static void main(String[] args) {
//        SpringApplication.run(HhtplatApplication.class, args);
        //构造一个webClient 模拟Chrome 浏览器
        WebClient webClient = new WebClient(BrowserVersion.CHROME);
//支持JavaScript
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setActiveXNative(false);
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setThrowExceptionOnScriptError(true);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());//很重要，设置支持AJA
        CookieManager cookieManager = new CookieManager();
        String url = "https://blog.csdn.net/lzjzy520/article/details/41597089";
        HtmlPage rootPage = null;
        try {
            rootPage = webClient.getPage(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
//设置一个运行JavaScript的时间
        webClient.waitForBackgroundJavaScript(30000);
        String html = rootPage.asXml();
        String s = rootPage.getCharset().name();
        Document document = Jsoup.parse(html);
    }
}
